package com.blb.order_service.service;

import com.blb.order_service.entity.Goods;
import com.blb.order_service.entity.Order;
import com.blb.order_service.util.MockData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    private GoodsService goodsService;

    /**
     * 查询所有订单
     * @return
     */
    public List<Order> findAllOrders(){
        MockData.orders.forEach(order -> {
            //请求服务提供者
            Goods goods = goodsService.findGoodsById(order.getGoodsId());
            order.setGoods(goods);
        });
        return MockData.orders;
    }

    public Order findOrderById(Long id){
        for(Order order : MockData.orders){
            if(id == order.getId()){
                //请求服务提供者
                Goods goods = goodsService.findGoodsById(order.getGoodsId());
                order.setGoods(goods);
                return order;
            }
        }
        return null;
    }
}
